home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
largef1a
/
frmmain.frm
< prev
Wrap
Text File
|
1999-09-19
|
15KB
|
432 lines
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmMain
BorderStyle = 1 'Fixed Single
Caption = "File Splitter"
ClientHeight = 3315
ClientLeft = 45
ClientTop = 330
ClientWidth = 3765
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3315
ScaleWidth = 3765
StartUpPosition = 2 'CenterScreen
Begin VB.ComboBox cmbSplitSize
Height = 315
Left = 120
Style = 2 'Dropdown List
TabIndex = 10
Top = 960
Width = 1335
End
Begin VB.Frame fraStats
Caption = "Statistics"
Height = 1335
Left = 120
TabIndex = 6
Top = 1800
Width = 3495
Begin VB.Label lblFileCount
AutoSize = -1 'True
Caption = "File Count:"
Height = 195
Left = 120
TabIndex = 12
Top = 240
Width = 750
End
Begin VB.Label lblElapsed
AutoSize = -1 'True
Caption = "Elapsed Time:"
Height = 195
Left = 120
TabIndex = 9
Top = 960
Width = 1005
End
Begin VB.Label lblFinish
AutoSize = -1 'True
Caption = "Finish Time:"
Height = 195
Left = 120
TabIndex = 8
Top = 720
Width = 840
End
Begin VB.Label lblStart
AutoSize = -1 'True
Caption = "Start Time:"
Height = 195
Left = 120
TabIndex = 7
Top = 480
Width = 765
End
End
Begin VB.CommandButton cmdBrowse
Caption = "..."
Height = 255
Left = 3360
TabIndex = 4
Top = 360
Width = 255
End
Begin VB.TextBox txtFileName
Height = 285
Left = 120
TabIndex = 3
Top = 360
Width = 3135
End
Begin VB.CommandButton cmdJoin
Caption = "Join File"
Enabled = 0 'False
Height = 375
Left = 2640
TabIndex = 2
Top = 960
Width = 975
End
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 255
Left = 120
TabIndex = 1
Top = 1440
Width = 3495
_ExtentX = 6165
_ExtentY = 450
_Version = 393216
Appearance = 1
Scrolling = 1
End
Begin VB.CommandButton cmdSplit
Caption = "Split File"
Default = -1 'True
Enabled = 0 'False
Height = 375
Left = 1560
TabIndex = 0
Top = 960
Width = 975
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 3120
Top = 120
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Label lblSplitSize
AutoSize = -1 'True
Caption = "Split Size (KB)"
Height = 195
Left = 120
TabIndex = 11
Top = 720
Width = 990
End
Begin VB.Label lblFileName
AutoSize = -1 'True
Caption = "Filename:"
Height = 195
Left = 120
TabIndex = 5
Top = 120
Width = 675
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Function SplitFiles(ByVal inputFilename As String, newFileSizeBytes As Long) As Boolean
Dim fReadHandle As Long
Dim fWriteHandle As Long
Dim fSuccess As Long
Dim lBytesWritten As Long
Dim lBytesRead As Long
Dim ReadBuffer() As Byte
Dim TotalCount As Long
Dim StartTime As Date
Dim FinishTime As Date
Dim StartTimeDouble As Double
Dim FinishTimeDouble As Double
Dim Count As Integer
' User Interface Stuff
StartTime = Now
StartTimeDouble = getTime
Me.MousePointer = vbHourglass
cmdJoin.Enabled = False
cmdSplit.Enabled = False
lblStart = "Start Time: " & StartTime
ProgressBar1.Max = FileLen(inputFilename)
ProgressBar1.Value = 0
Count = 1
' Resize Byte Array for Read
ReDim ReadBuffer(0 To newFileSizeBytes)
' Determine Total Number of Output Files for User Interface Only
TotalCount = (FileLen(inputFilename) \ UBound(ReadBuffer)) + 1
' Open Read File Handle
fReadHandle = CreateFile(inputFilename, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
' If Successful read, continue
If fReadHandle <> INVALID_HANDLE_VALUE Then
' Read First File Block
fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
' Increment ProgressBar
ProgressBar1.Value = ProgressBar1.Value + lBytesRead
ProgressBar1.Refresh
' Loop while not EOF
Do While lBytesRead > 0
' Update File Count Statistic on User Interface
lblFileCount.Caption = "Split Count: " & Count & " of " & TotalCount
lblFileCount.Refresh
' Open Write File Handle
If Dir(inputFilename & "." & Count) <> "" Then
Kill inputFilename & "." & Count
End If
fWriteHandle = CreateFile(inputFilename & "." & Count, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
' If Successful Write, Continue
If fWriteHandle <> INVALID_HANDLE_VALUE Then
' Write Data Block to File
fSuccess = WriteFile(fWriteHandle, ReadBuffer(0), lBytesRead, lBytesWritten, 0)
If fSuccess <> 0 Then
' Required to Write to File
fSuccess = FlushFileBuffers(fWriteHandle)
' Close Write File
fSuccess = CloseHandle(fWriteHandle)
Else
' On Failure Quit
lblFileCount.Caption = "Split Count: Write Error"
SplitFiles = False
Exit Function
End If
Else
' On Failure Quit
lblFileCount.Caption = "Split Count: Write Error"
SplitFiles = False
Exit Function
End If
' Get the next Read Block
fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
' Increment ProgressBar
ProgressBar1.Value = ProgressBar1.Value + lBytesRead
ProgressBar1.Refresh
' Increment Count
Count = Count + 1
Loop
' Close Read File
fSuccess = CloseHandle(fReadHandle)
Else
' On Failure Quit
lblFileCount.Caption = "Split Count: Read Error"
SplitFiles = False
Exit Function
End If
' User Interface Stuff